package com.fz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fz.entity.PropertyFee;
import com.fz.entity.Repair;
import com.fz.entity.Visitor;
import com.fz.service.RepairService;
import com.fz.service.VisitorService;
import com.fz.vo.ResultVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fz
 * @since 2024-08-21
 */
@RestController
@RequestMapping("/visitor")
public class VisitorController {
    @Resource
    VisitorService visitorService;
    @GetMapping("/list")
    List<Visitor> list(){return visitorService.list();}
    @PostMapping("/add")
    ResultVo<Boolean>add(String type, String aging, Integer count, String content, Integer userId, String username){
        return ResultVo.success(visitorService.add(type,aging,count,content,userId,username),"访客申请提交成功");
    }
    @PostMapping("/pass")
    ResultVo<Boolean> pass(Long id,Integer status,Integer statu){
        return ResultVo.success(visitorService.pass(id,status,statu),"已成功放行游客！");
    }
    @PostMapping("/reject")
    ResultVo<Boolean> reject(Long id,Integer status,Integer statu){
        return ResultVo.success(visitorService.reject(id,status,statu),statu==2?"该游客已禁止通行！":"重置游客状态成功，请尽快处理！");
    }

    @GetMapping("/getById")
    ResultVo<Visitor> getById(Long id)
    {
        return ResultVo.success(visitorService.getById(id));
    }
    @GetMapping("/check")
    ResultVo<Boolean>check(Long id,String field,String value){
        return ResultVo.success(visitorService.check(id,field,value));
    }

    @PostMapping("/update")
    ResultVo<Boolean> update(Visitor visitor){
        return ResultVo.success(visitorService.updateById(visitor),"修改访客申请表单成功");
    }
    @PostMapping("/llist")
    ResultVo<IPage<Visitor>>llist(String username, Integer pageNo, Integer pageSize)
    {return ResultVo.success(visitorService.getList(username, pageNo, pageSize));}
    @PostMapping("/list2")
    ResultVo<IPage<Visitor>> list2(Integer pageNo, Integer pageSize){
        return ResultVo.success(visitorService.showList( pageNo, pageSize));
    }


    @PostMapping("/del")
    ResultVo<Boolean>del(Long id,Integer status)
    {
        return ResultVo.success(visitorService.del(id,status),"撤销访客表单成功");
    }
    @PostMapping("/search")
    ResultVo<IPage<Visitor>> search(String input, Integer pageNo, Integer pageSize){
        return ResultVo.success(visitorService.search(input,pageNo,pageSize),"搜索成功");
    }

}
